import service from "../utils/request";
import ajax from '@/utils/ajax'
    /*
     *  获取商品接口
     */
    export function getCategoryList(requestData) {
        return service.request({
            url:'/manage/category/list',
            method:'get',
            params:{parentId:requestData}
        })
    }
    
    /*
    获取产品列表
    */
     export const reqProducts=(pageNum,pageSize)=>ajax('http://120.55.193.14:5000/manage/product/list',{pageNum,pageSize}) 

    /*
    根据产品名称或描述进行搜索
    */
     export const searchProducts=({searchContent,pageNum,pageSize,searchType})=>ajax('http://120.55.193.14:5000/manage/product/search',{pageNum,pageSize,[searchType]:searchContent})

    /*
    获取一个分类
    */

     export const reqCategory = (categoryId) => ajax('http://120.55.193.14:5000/manage/category/info', {categoryId})

     /*
     更新商品的状态(上架/下架)
     */
     export const reqUpdateStatus = (productId, status) => ajax('http://120.55.193.14:5000/manage/product/updateStatus', {productId, status}, 'POST')
  
    /*
    获取一级/二级分类的列表
    */
    export const reqCategorys = (parentId) => ajax('http://120.55.193.14:5000/manage/category/list', {parentId})

    /*
     删除上传的已上传的图片
     */
    export const reqDeleteImg = (name) => ajax('http://120.55.193.14:5000/manage/img/delete', {name}, 'POST')
  
    /*
     添加分类
     */
     export const reqAddUpdateProduct = (product) => ajax('http://120.55.193.14:5000/manage/product/'+(product._id?'update':'add'), product, 'POST')
  
    /*
     *  新增商品接口
     */
    export function addCategory(requestData) {
        return service.request({
            url:'/addCategory/',
            method:'post',
            params:requestData
        })
    }
    /*
     *  更新商品接口
     */
    export function updateCategory(requestData) {
        return service.request({
            url:'/updateCategory/',
            method:'post',
            params:requestData
        })
    }
     /*
      *  删除商品接口
      */
    export function deleteCategory(pid){
        let data
        if(!Array.isArray(pid))
        data = [pid]
        else
        data = pid
        return service.request({
            url:'/deleteManyCategory/',
            method:'post',
            data:{'data':data}
        }) 
    }
     /*
      *  id获取某商品接口
      */
    export function getCategoryByID(pid){
        return service.request({
            url:'/getCategoryByID/',
            method:'post',
            params:{"pid":pid},
            headers: {
                'Content-Type': 'application/json; charset=UTF-8'
            }
        })
    }

    /*
     * 根据关键字获取商品
     */
    export function  getCategoryByKeyWord(KeyWord){
        return service.request({
            url:'/getCategoryByKeyWord/',
            method:'post',
            params:{"KeyWord":KeyWord}
        })
    }

     
    